package com.web.shop.repository;


import com.web.shop.document.EsItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface EsItemRepository extends ElasticsearchRepository<EsItem,Long> {

    //根据title和brand查询 ，分页
    public Page<EsItem> findByTitleAndBrand(String title, String brand, Pageable pageable);

    @Query("{\"multi_match\": {\n" +
            "      \"query\": \"?0\",\n" +
            "      \"fields\": [\"title\",\"category\"]\n" +
            "    }}")
    public Page<EsItem> findByKeyword(String keyword, Pageable pageable);

    @Query( "  {\n" +
            "   \"prefix\": {\n" +
            "     \"title\": {\n" +
            "       \"value\": \"?0\"\n" +
            "     }\n" +
            "   }\n" +
            "  }")
    public Page<EsItem> findItemByPrefixKeyword(String prefix,Pageable pageable);

}
